package com.yanqu.road.server.logic.activity.condition.musicroom;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.channelmusicroom.ChannelMusicRoomRankActivityModule;
import com.yanqu.road.server.gameplayer.module.musicroom.MusicRoomRankActivityModule;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseNewRankActivityCondition;
import com.yanqu.road.server.manger.cross3.ChannelRankActivityMgr;
import com.yanqu.road.utils.math.BigSurdVec;

import java.math.BigInteger;

public class MusicRoomScoreRankCondition extends BaseNewRankActivityCondition {
    public MusicRoomScoreRankCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        long userRankScore = 0;
        if (activityInfo.getType() == eActivityType.MusicRoomRank.getValue()){
            userRankScore =player.getModule(MusicRoomRankActivityModule.class).getUserRankScore();
        } else if (activityInfo.getType() == eActivityType.ChannelMusicRoomRank.getValue()) {
            userRankScore = player.getModule(ChannelMusicRoomRankActivityModule.class).getUserRankScore();
        }else {
            return;
        }

        setValue(BigInteger.valueOf(userRankScore));
        //如果是跨域百花
        if (activityInfo.getType() == eActivityType.ChannelMusicRoomRank.getValue()) {
            ChannelRankActivityMgr.userRankChange(activityInfo.getActivityId(), activityConditionInfo.getType(), getValue().longValue(), player.getUserId(),"");
            //区域榜单用原来的区服榜type
            ChannelRankActivityMgr.channelRankPartChange(activityInfo.getActivityId(), eGamePlayerEventType.ServerMusicRoomScoreRank.getValue(), getValue().longValue(), player.getUserId());
        }else {
            rankChange();
        }

    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.MusicRoomScoreRank.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.MusicRoomScoreRank.getValue(), handle);
    }

    @Override
    public boolean canChange(ActivityInfo activityInfo) {
        return true;
    }
}
